﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gemGenerator
{
    class Matrix3
    { //for rotation of the gem preview
        public static Matrix3 RotationX(double angle)
        {
            double c = Math.Cos(angle), s = Math.Sin(angle);
            double[] vals = {   1, 0, 0,
                                0, c, -s,
                                0, s, c };
            return new Matrix3(vals);
        }
        public static Matrix3 RotationY(double angle)
        {
            double c = Math.Cos(angle), s = Math.Sin(angle);

            double[] vals = {   c, 0, s,
                                0, 1, 0,
                                -s,0, c };
            return new Matrix3(vals);
        }
        public static Matrix3 RotationZ(double angle)
        {
            double c = Math.Cos(angle), s = Math.Sin(angle);

            double[] vals = {   c,-s,0,
                                s,c,0,
                                0,0,1 };
            return new Matrix3(vals);
        }
        public static Matrix3 Identity()
        {
            double[] vals = {   1,0,0,
                                0,1,0,
                                0,0,1 };
            return new Matrix3( vals );
        }

        public static Matrix3 operator *(Matrix3 a, Matrix3 b)
        {
            double[] vals = {0,0,0,0,0,0,0,0,0};
            for (int i = 0; i < 3; ++i)
                for (int j = 0; j < 3; ++j)
                    for (int k = 0; k < 3; ++k)
                        vals[3 * i + j] += a.vals[3 * i + k] * b.vals[3 * k + j];
            return new Matrix3(vals);
        }
        public static VectorD operator *(Matrix3 a, VectorD v)
        {
            return new VectorD(a.vals[0] * v.X + a.vals[1] * v.Y + a.vals[2] * v.Z,
                                       a.vals[3] * v.X + a.vals[4] * v.Y + a.vals[5] * v.Z,
                                       a.vals[6] * v.X + a.vals[7] * v.Y + a.vals[8] * v.Z);
        }
        private Matrix3(double[] vals)
        {
            this.vals = vals;
        }
        double[] vals;
    }
}
